package com.oron3.bouncer;


import javax.microedition.khronos.opengles.GL;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.widget.TextView;

import com.oron3.bouncer.genericgl.BallRenderer;
import com.oron3.bouncer.genericgl.BallWorld;
import com.oron3.bouncer.genericgl.MatrixTrackingGL;
import com.oron3.bouncer.interaction.AndroidInteractionInterpreter;
import com.oron3.bouncer.interaction.Repainter;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 *
 * @see SystemUiHider
 */
public class BouncyBallActivity extends Activity {
	public static TextView textView;

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_bouncy_ball);
		mGLSurfaceView = (GLSurfaceView)findViewById(R.id.surfaceView1);
		mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

		textView = (TextView) findViewById(R.id.textView);
		final AndroidInteractionInterpreter a = new AndroidInteractionInterpreter(this, new Repainter() {

			@Override
			public void repaint() {
				mGLSurfaceView.requestRender();
			}
		});
		mGLSurfaceView.setOnTouchListener(a);
		mGLSurfaceView.setGLWrapper(new GLSurfaceView.GLWrapper() {
			@Override
			public GL wrap(final GL gl) {
				return new MatrixTrackingGL(gl);
			}});
		final BallWorld ballWorld = new BallWorld();
		ballWorld.setInterpreter(a);
		mGLSurfaceView.setRenderer(new BallRenderer(ballWorld));
		//mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

		//mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
	}


	@Override
	protected void onResume() {
		// Ideally a game should implement onResume() and onPause()
		// to take appropriate action when the activity looses focus
		super.onResume();
		mGLSurfaceView.onResume();
	}

	@Override
	protected void onPause() {
		// Ideally a game should implement onResume() and onPause()
		// to take appropriate action when the activity looses focus
		super.onPause();
		mGLSurfaceView.onPause();
	}

	private GLSurfaceView mGLSurfaceView;
}
